setwd("E:/5hmc_file/2_5hmc_yjp_bam/ASM")
file=read.csv("20201124/same.direction.dowdown.upup.csv",head=T)
file$group.CC=rowSums(!is.na(file[,8:15]),na.rm = T)
file$group.HC=rowSums(!is.na(file[,16:23]),na.rm = T)

file$pattern.no.dupl.DC=""
for (i in 1:dim(file)[1]) {
  str1=as.character(c(unlist(as.matrix(file[i,2:7]))))
  str1=unique(str1[!is.na(str1)])
  str1=paste(str1,sep=":",collapse = ":")
  file[i,"pattern.no.dupl.DC"]=str1
}

file$pattern.no.dupl.CC=""
for (i in 1:dim(file)[1]) {
  str1=as.character(c(unlist(as.matrix(file[i,8:15]))))
  str1=unique(str1[!is.na(str1)])
  str1=paste(str1,sep=":",collapse = ":")
  file[i,"pattern.no.dupl.CC"]=str1
}

file$pattern.no.dupl.HC=""
for (i in 1:dim(file)[1]) {
  str1=as.character(c(unlist(as.matrix(file[i,16:23]))))
  str1=unique(str1[!is.na(str1)])
  str1=paste(str1,sep=":",collapse = ":")
  file[i,"pattern.no.dupl.HC"]=str1
}
write.csv(file,"20201124/same.direction.dowdown.upup.modify.csv",quote=F,row.names = F)
cup=file
###DC.1
sel=which(file$pattern.no.dupl.DC=="up:down"|file$pattern.no.dupl.DC=="down:up")
file1=file[-sel,]
DC.1=file1[file1$group.DC.num>=1,]

sel=which(file$pattern.no.dupl.CC=="up:down"|file$pattern.no.dupl.CC=="down:up")
file1=file[-sel,]
CC.2=file1[file1$group.CC>=2,]

sel=which(file$pattern.no.dupl.HC=="up:down"|file$pattern.no.dupl.HC=="down:up")
file1=file[-sel,]
HC.2=file1[file1$group.HC>=2,]

length(unique(c(DC.1$unitID,CC.2$unitID,HC.2$unitID)))
###
sel=which(file$pattern.no.dupl.DC=="up:down"|file$pattern.no.dupl.DC=="down:up")
file1=file[-sel,]
DC.6=file1[file1$group.DC.num==6,]

sel=which(file$pattern.no.dupl.CC=="up:down"|file$pattern.no.dupl.CC=="down:up")
file1=file[-sel,]
CC.8=file1[file1$group.CC==8,]

sel=which(file$pattern.no.dupl.HC=="up:down"|file$pattern.no.dupl.HC=="down:up")
file1=file[-sel,]
HC.8=file1[file1$group.HC==8,]

length(unique(c(DC.6$unitID,CC.8$unitID,HC.8$unitID)))
